cd "${mystart}/Simulated data\Calibration/Benchmark Data/"
	
* Table 63
* AVERAGE WAGES by age group
qui{
clear
use "Data files/Benchmark.dta"
keep if  emp_ft_pt==2 & H==3
drop if wage_noise<3.12
replace wage_noise=80 if wage_noise>80 & wage_noise!=.

drop age_group*
rename age AGE_YR1

gen age_group=1 if AGE_YR1>=25 & AGE_YR1<30
replace age_group=2 if AGE_YR1>=35 & AGE_YR1<40
replace age_group=3 if AGE_YR1>=45 & AGE_YR1<50
replace age_group=4 if AGE_YR1>=55 & AGE_YR1<60
drop if age_group==.
label var age_group "Age Group"
label define lbl_age 1 "Ages 25-29" 2 "Ages 35-39" 3 "Ages 45-49" 4 "Ages 55-59"
label values age_group lbl_age

table ( age_group) (education),  statistic(mean wage_noise) nototals nformat(%5.1f) 
collect title "Average Wages, FT Workers in Good H, Model"
collect export "${out_tables}/Target_av_wages.tex", tableonly replace
}

*Table 64
* AVERAGE WAGES  by H
qui{
clear
use "Data files/Benchmark.dta"
keep if  emp_ft_pt==2
drop if wage_noise<3.12
replace wage_noise=80 if wage_noise>80 & wage_noise!=.
drop age_group*
rename age AGE_YR1
drop if AGE_YR1<40 & AGE_YR1>50

table ( H) (education),  statistic(mean wage_noise) nototals nformat(%5.1f) 
collect title "Average Wages, FT Workers by H, ages 40-50, Model"
collect export "${out_tables}/Target_av_wages2.tex", tableonly replace
}


* Table 65
*  PT/FT wages
qui{
clear
use "Data files/Benchmark.dta"
drop if wage_noise<3.12
replace wage_noise=80 if wage_noise>80 & wage_noise!=.
drop if emp_ft_pt==0
keep  if age>=30 & age<=55

collapse (mean)  wage_noise, by(education emp_ft_pt)
reshape wide wage_noise, i(education) j(emp_ft_pt)
gen ratio=wage_noise1/wage_noise2

label var ratio "PT/FT Wage Ratio"
table  (education),  statistic(mean ratio) nototals nformat(%5.2f) 
collect title "Average PT to FT Wages, ages 30-55, Model"
collect export "${out_tables}/Target_av_wages3.tex", tableonly replace
}


* Table 67
* percentiles of FE, wage regression
qui{
clear
use "Data files/Benchmark.dta"
sort ID age
tabstat wage_noise, stat(mean p50 p90 p95 p99 max)
replace wage_noise=. if  wage_noise<3.5  //(min wage)
replace wage_noise=. if  wage_noise>90

gen log_real_av_wage= log(wage_noise)  if emp_ft_pt==2 // FT wages only
gen log_real_av_wage_all= log(wage_noise)  // all

rename ID id

	    gen I_work_lagged = 0 if emp_ft_pt[_n-1]!=2 & id==id[_n-1] & age==age[_n-1]+1
	replace I_work_lagged = 1 if emp_ft_pt[_n-1]==2 & id==id[_n-1] & age==age[_n-1]+1
	replace I_work_lagged = 2 if emp_ft_pt[_n-1]==1 & id==id[_n-1] & age==age[_n-1]+1 
	
	gen exp_full=hours/40
	 replace exp_full=exp_full[_n-1]+exp_full if id==id[_n-1]
	 gen exp_full_sq=exp_full^2
	 
	 keep if age>=30 & age<=55
	 
gen NE_lagged1 = 0 if I_work_lagged == 1 | I_work_lagged == 2
replace NE_lagged1 = 1 if I_work_lagged == 0

label var NE_lagged1 "Lagged Non-employed"
label define lab_ne_lagged 0 "Employed Last Yr" 1 "Not Employed Last Yr"
label values NE_lagged1 lab_ne_lagged

egen x=count(log_real_av_wage_all), by(id)
drop if x<6
drop x

xtset id age

* by educ
xtreg log_real_av_wage_all age age_sq  if education==1, fe  
predict individual_effect1 if education==1, u

xtreg log_real_av_wage_all age age_sq  if education==2, fe   
predict individual_effect2 if education==2, u

xtreg log_real_av_wage_all age age_sq  if education==3, fe  
predict individual_effect3 if education==3, u

gen individual_effect = individual_effect1 if education==1
replace individual_effect = individual_effect2 if education==2
replace individual_effect = individual_effect3 if education==3

collapse (max) individual_effect education, by(id)

label var education "Education"
label define educ1 1 "HS or Less" 2 "Some College" 3 "College"
label values education educ1 
table education ,   stat(p25 individual_effect) stat(p50 individual_effect) stat(p75 individual_effect) nototal nformat(%5.2f) 
collect label levels result p25 "25th", modify
collect label levels result p50 "50th", modify
collect label levels result p75 "75th", modify
collect title "Percentiles of Individual Fixed Effects, Wage regression, Model, Ages 30-55"
collect export "${out_tables}/FE_distribution.tex", tableonly replace

}

* Table 68
* AVERAGE WAGES WITHIN WAGE TERCILES
qui{
*top panel
clear
use "Data files/Benchmark.dta"
keep if  emp_ft_pt==2

drop if wage_noise<3.35

drop if wage_noise> 100
replace wage_noise=94.34 if wage_noise>94.34 & wage_noise!=.

rename wage_noise incwage_hourly
rename education college_alt

egen wage_tercile = xtile(incwage_hourly) if age>=40 & age<=50, by(college_alt) n(3)
label var wage_tercile "Wage Tercile"
label define inc_t 1 "1st" 2 "2nd" 3 "3rd" 
label values wage_tercile inc_t

table college_alt wage_tercile if  age>=40 & age<=50,  statistic(mean incwage_hourly) nototals nformat(%5.1f) 
collect title "Average Wages by Terciles, ages 40-50, FT Workers, Model"
collect export "${out_tables}/CPS_Wage_terc.tex", tableonly replace


* bottom panel
clear
use "Data files/Benchmark.dta"
sort ID age
keep if age<65
replace wage_noise=. if  wage_noise<3.5 
keep if employed_yn==1
rename wage_noise incwage_hourly

keep if age>=40 & age<=50
replace age_group = 50 if age>=50 & age<=55
		
collapse (p5) p5=incwage_hourly (p25) p25=incwage_hourly (p50) p50=incwage_hourly (p75) p75=incwage_hourly (p90) p90=incwage_hourly (p95) p95=incwage_hourly (p99) p99=incwage_hourly , by (education )	
* copy paste into table 68 bottom panel .
}
	

